const mongoose = require('mongoose')

const Schema = mongoose.Schema

const CategorySchema = new Schema({
  name: {
    type: String,
    require: true,
    unique: true,
  },
})

CategorySchema.virtual('TypeList', {
  ref: 'Type',
  localField: '_id',
  foreignField: 'category_id',
  justOne: false,
})
CategorySchema.set('toObject', { virtuals: true })
CategorySchema.set('toJSON', { virtuals: true })

const CategoryModel = mongoose.model('Category', CategorySchema)

module.exports = CategoryModel
